package com.lhl.demo.domain.entity;

import com.lhl.fw.db.entity.BaseEntity;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.HashSet;
import java.util.Set;

@Entity
@Getter
@Setter
@NoArgsConstructor
@Table(name="ORDERS")
public class Order extends BaseEntity<String> {

	private Float amount;
	@OneToMany(mappedBy="order",cascade=CascadeType.ALL)
	private Set<OrderItem> orderItems = new HashSet<>();
	
	public void addItem(OrderItem orderItem) {
		this.orderItems.add(orderItem);
		orderItem.setOrder(this);
	}
	
	public void removeItem(OrderItem orderItem) {
		if(this.orderItems.contains(orderItem)) {
			this.orderItems.remove(orderItem);
		}
	}
}
